<template>
  <div>
    <p-form-model :model="form" :rules="rules" layout="inline">
      <p-form-model-item label="商机编号">
        <p-input v-model="form.opportunityNo" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="商机名称">
        <p-input v-model="form.opportunityName" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="客户简称">
        <p-input v-model="form.customerShortName" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="销售组织">
        <SelectOrg v-model="form.salesOrgCode" />
      </p-form-model-item>
      <p-button type="primary" class="btn-search" @click="handleSearch">
        搜索
      </p-button>
      <p-form-model-item label="当前状态">
        <SelectDefault
          v-model="form.currStatus"
          code="business_transfer_process_status"
        />
      </p-form-model-item>
      <p-form-model-item label="当前节点">
        <SelectDefault v-model="form.opportunityStage" :options="node" />
      </p-form-model-item>
      <p-form-model-item label="创建人">
        <p-input v-model="form.createUserName" placeholder="请输入" />
      </p-form-model-item>
      <p-form-model-item label="创建时间">
        <p-range-picker
          v-model="form.creatTime"
          :placeholder="['开始时间', '结束时间']"
          format="YYYY-MM-DD"
          :mode="mode"
          :value="value"
          @change="changeTime"
        />
      </p-form-model-item>
      <p-button style="margin-right: 20px" @click="handleReset">重置</p-button>
    </p-form-model>
  </div>
</template>
<script>
import monent from 'moment';
import { getDicList } from '@/api/public.js';
const defaultForm = {
  opportunityNo: undefined,
  opportunityName: undefined,
  customerShortName: undefined,
  salesOrgCode: undefined,
  currStatus: undefined,
  opportunityStage: undefined,
  createUserName: undefined,
  creatTime: undefined,
  startCreateTime: undefined,
  endCreateTime: undefined,
};
export default {
  data() {
    return {
      node: [],
      form: {
        ...defaultForm,
        mode: ['date', 'date'],
        value: [],
      },
    };
  },
  created() {
    this.getDicList();
  },
  methods: {
    async getDicList() {
      const res = await getDicList('business_transfer_process_node');
      const nodeOption = res?.data?.data || [];
      this.node = [
        { label: '全部', value: '' },
        ...nodeOption.filter(item => item.sort !== 1),
      ];
    },
    handleSearch() {
      this.$emit('search', this.form);
    },
    handleReset() {
      this.form = { ...defaultForm };
      this.$emit('search', this.form);
    },
    changeTime(value) {
      this.value = value;
      this.form.startCreateTime =
        monent(value[0]).format('YYYY-MM-DD') + ' ' + '00:00:00';
      this.form.endCreateTime =
        monent(value[1]).format('YYYY-MM-DD') + ' ' + '23:59:59';
    },
  },
};
</script>

<style lang="less" scoped>
.poros-form {
  box-sizing: border-box;
  background-color: #f7f7f8;
  padding: 10px;
  padding-bottom: 0px;
  width: 100%;
}
.poros-form-item {
  width: 20%;
  margin-bottom: 10px;
}
/deep/ .poros-form-item-control-wrapper {
  width: calc(100% - 70px);
}
.btn-search {
  margin-right: 16px;
}
/deep/ .poros-form-item-label {
  width: 70px;
}
</style>
